package com.example.rootwar.search;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class day1203 {

    public static void main(String[] args) {
        //4 3 -1 2 5
        // 4 2 3

//            int [] nums={-4,-2,-3};
//            int k=4;
//        int i = largestSumAfterKNegations(nums, k);
//        System.out.println(i);

        List<String> duichen = getDuichen(20, 20000);

        for (String s : duichen) {
            System.out.println(s);
        }
    }


    public static  List<String> getDuichen(int start,int end){

        List<String> res = new ArrayList<>();

        for (int i = start; i <=end ; i++) {

            String oneStr = String.valueOf(i);

            boolean isDuichen=true;

            char[] chars = oneStr.toCharArray();

            for (int j = 0; j <=(0+chars.length-1)/2 ; j++) {

                if (chars[j]!=chars[chars.length-1-j]){
                    isDuichen=false;
                    break;
                }

            }

            if (isDuichen){
                res.add(oneStr);

            }
        }
        return res;
    }






    public static int largestSumAfterKNegations(int[] nums, int k) {

        List<Integer> list = new ArrayList<>();
        for (int i : nums) {
            list.add(i);
        }
        Comparator<Integer> comparator = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.intValue()-o2.intValue();
            }
        };
        list.sort(comparator);


        int count=0;
        int tail=0;
        for (; tail < list.size(); tail++) {
            int integer = list.get(tail);
            if (integer<0){
                count++;
            }else {
                break;
            }

        }

        int sum=0;
        if (k<=count){

            for (int i = 0; i < list.size(); i++) {

                if (i<=k-1){
                    sum-=list.get(i);
                }else {
                    sum+=list.get(i);
                }

            }

        }else if (k>count){
             k=(k-count)%2;
             if (k==1){

                 for (int i = 0; i < list.size(); i++) {
                     sum+=Math.abs(list.get(i));
                 }
                 if (count>=list.size()){
                     sum=sum-2*Math.abs(list.get(count-1));
                 }else {
                     if (count==0){
                         sum=sum-2*Math.min(Math.abs(list.get(count)),Math.abs(list.get(count)));
                     }else {
                         sum=sum-2*Math.min(Math.abs(list.get(count-1)),Math.abs(list.get(count)));
                     }

                 }


             }else if (k==0){

                 for (int i = 0; i < list.size(); i++) {

                    sum+=Math.abs(list.get(i));


                 }

             }

        }

    return sum;

    }



}
